package com.yy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yy.pojo.Stock;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface StockMapper extends BaseMapper<Stock> {
    @Update("update tb_stock set count=count-#{count} where product_code=#{productCode} and count>=#{count}")
    int updateStock(@Param("productCode") String productCode, @Param("count") Integer count);

    @Select("select * from tb_stock where product_code=#{productCode} for update")
    List<Stock> queryStock(@Param("productCode") String productCode);
}
